//
//  LandmarkDetail.swift
//  codelabs
//
//  Created by 雷雷 on 23/05/2025.
//

import SwiftUI

struct LandmarkDetail: View {
    @Environment(ModelData.self) var modelData
    var landmark:Landmark
    
    var landmarkIndex:Int{
        modelData.landmarks.firstIndex(where: {$0.id==landmark.id})!
    }
    
    var body: some View {
        @Bindable var modelData = modelData
        
        VStack(){
            
            // 地图
            MapView(coordinate:landmark.locationCoordinate)
                .frame(height: 300)
            
            // 图像
            landmark.image
                .resizable()
                .clipShape(.circle)
                .overlay{
                    // 边框
                    Circle().stroke(.gray,lineWidth: 1)
                }
                .shadow(radius: 8)
                .offset(y:-130)
                .padding(.bottom,-130)
        }
        
        // 标题、内容
        VStack(alignment:.leading){
            
            HStack {
                Text(landmark.name).font(.title)
                FavoriteButton(isSet: $modelData.landmarks[landmarkIndex].isFavorite)
            }
            
            HStack{
                
                Text(landmark.park)
                    
                Spacer()
                
                Text(landmark.state)
                   
            }
            .font(.subheadline)
            .foregroundStyle(.secondary)
            
            Divider()
            
            Text("About \(landmark.name)")
                .font(.title2)
            Text(landmark.description)
            
        }.padding()
        
        Spacer()
    
        }
    }

#Preview {
    LandmarkDetail(landmark: ModelData().landmarks[1])
        .environment(ModelData())
}
